﻿using mvcForum.Web.Attributes;
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;

using mvcForum.Core;
using System.IO;

namespace mvcForum.Web.ViewModels.Update {

	public class UpdateUserViewModel {

		public UpdateUserViewModel() : base() { }

		public UpdateUserViewModel(ForumUser user, Boolean external, Boolean allowUserTheme, String themeRoot)
			: base() {

			this.Culture = user.Culture;
			this.Timezone = user.Timezone;
			this.FullName = user.FullName;
			this.Name = user.Name;
			this.Email = user.EmailAddress.EndsWith("repl@ce.this") ? String.Empty : user.EmailAddress;
			this.Id = user.Id;
			this.ExternalUser = external;
			this.AllowUserTheme = allowUserTheme;
			this.Theme = user.Theme;
			this.Themes = new String[] { };
			if (this.AllowUserTheme && Directory.Exists(themeRoot)) {
				this.Themes = Directory.GetDirectories(themeRoot).Select(d => d.Substring(themeRoot.Length + 1)).ToArray();
			}
		}

		[Required]
		public Int32 Id { get; set; }
		[Required]
		[LocalizedDisplay(typeof(mvcForum.Web.ViewModels.Update.UpdateUserViewModel), "Culture")]
		public String Culture { get; set; }
		[Required]
		[LocalizedDisplay(typeof(mvcForum.Web.ViewModels.Update.UpdateUserViewModel), "Timezone")]
		public String Timezone { get; set; }
		[LocalizedDisplay(typeof(mvcForum.Web.ViewModels.Update.UpdateUserViewModel), "FullName")]
		public String FullName { get; set; }
		[LocalizedDisplay(typeof(mvcForum.Web.ViewModels.Update.UpdateUserViewModel), "Name")]
		public String Name { get; set; }
		[Required]
		[LocalizedDisplay(typeof(mvcForum.Web.ViewModels.Update.UpdateUserViewModel), "Email")]
		public String Email { get; set; }
		[LocalizedDisplay(typeof(mvcForum.Web.ViewModels.Update.UpdateUserViewModel), "OldPassword")]
		public String OldPassword { get; set; }
		[LocalizedDisplay(typeof(mvcForum.Web.ViewModels.Update.UpdateUserViewModel), "NewPassword")]
		public String NewPassword { get; set; }
		[LocalizedDisplay(typeof(mvcForum.Web.ViewModels.Update.UpdateUserViewModel), "RepeatNewPassword")]
		public String RepeatedNewPassword { get; set; }
		[LocalizedDisplay(typeof(mvcForum.Web.ViewModels.Update.UpdateUserViewModel), "Theme")]
		public String Theme { get; set; }

		public Boolean AllowUserTheme { get; set; }
		public String[] Themes { get; set; }

		public Boolean ExternalUser { get; private set; }
	}
}